<?php

include 'DBconn.php';

class RoleMaster {

    public function addRole($VObject) {
        mysql_query("INSERT INTO rolemaster(role_name,cre_userid,cre_datetime,activestatus) values('$VObject->role_name','$VObject->cre_userid','$VObject->cre_datetime',1)");
        $s = mysql_query($query) or die(mysql_error());
        if ($s == 1) {
            mysql_query("COMMIT");
        } else {
            mysql_query("ROLLBACK");
        }
        mysql_close($con);
        return $this->getAllRoles();
    }

    public function getAllRoles() {
        $result = mysql_query("SELECT * from role_header where activestatus=1");
        $ret = array();
        while ($row = mysql_fetch_object($result)) {
            $tmp = new VORole();
            $tmp->serialnumber = (int) $row->serialnumber;
            $tmp->role_name = $row->role_name;
            $tmp->cre_userid = (int) $row->cre_userid;
            $tmp->cre_datetime = $row->cre_datetime;
            $tmp->activestatus = $row->activestatus;
            $ret[] = $tmp;
        }
        mysql_free_result($result);
        mysql_close($con);
        return $ret;
    }

    public function updateRole($VObject) {
        $query = "update role_header set role_name='$VObject->role_name',cre_userid='$VObject->cre_userid',cre_datetime='$VObject->cre_datetime' where serialnumber='$VObject->serialnumber'";
        $s = mysql_query($query);
        if ($s == 1) {
            mysql_query("COMMIT");
        } else {
            mysql_query("ROLLBACK");
        }
        return $this->getAllRoles();
        mysql_close($con);
    }

    public function deleteRole($VObject) {
        $s = mysql_query("update role_header set activestatus=0 where serialnumber=" . $VObject->serialnumber) or die(mysql_error());
        if ($s == 1) {
            mysql_query("COMMIT");
        } else {
            mysql_query("ROLLBACK");
        }
        return $this->getAllRoles();
    }

}

class VORole {

    var $serialnumber;
    var $role_name;
    var $cre_userid;
    var $cre_datetime;
    var $activestatus;

}

?>